package com.study.webapp.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 数组移除元素
 */
public class Leet_27 {

	public static void main(String[] args) {
		int[] nums = new int[] {2,3,4,5,4,8};
		int val = 4;
		int a = removeElement(nums,val);
		System.out.println(a);
		System.out.println(Arrays.asList(nums));
	}


	public static int removeElement(int[] nums, int val) {
		int j = 0;
		for (int i = 0; i< nums.length;i++) {
			if (nums[i] != val) {
				nums[j] = nums[i];
				j++;
			}
		}
		return j;
	}

}
